var serviceTypeDict = [{
	value: '1,0,0,0,0',
	text: '安装'
}, {
	value: '0,1,0,0,0',
	text: '保内'
}, {
	value: '0,0,1,0,0',
	text: '保外'
}, {
	value: '0,0,0,1,0',
	text: '服务合同'
}, {
	value: '0,0,0,0,1',
	text: '其他'
}]

/**
 * 初始化点击事件
 */
function initClickEvent() {
	// 服务类型
	h('#serviceTypeName').tap(function() {
		app.hideSoftKeybord()
		var divi = h('#divi').val()
		if (divi == 'LSC' || divi == 'ESC' || divi == 'HSC') {
			var userPicker = new mui.PopPicker();
			userPicker.setData(serviceTypeDict);
			userPicker.show(function(items) {
				var self = plus.webview.currentWebview();
				if (h('#serviceResults').val() == '1' && items[0].text == '安装' && self.subServiceType == '安装') {
					h('#eqSignDiv').show();
				} else {
					h('#eqSignDiv').hide();
					var eqSigns = document.getElementsByName("eqSign");
					for (var i = 0; i < eqSigns.length; i++) {
						eqSigns[i].checked = false;
					}
				}
				if(items[0].text=='安装' || items[0].text=='保内'){
					h('#feeInfo').parent().hide()
				}else{
					h('#feeInfo').parent().show()
				}
				h('#serviceTypeName').html(items[0].text)
				h('#serviceType').val(items[0].text)
				userPicker.dispose()
			});
		}
	});

	// 查看关联的日志
	h('#worklog').tap(function() {
		app.hideSoftKeybord()
		app.jumpTo('worklog.html', 'view/service/report/fieldservice/worklog.html', {
			serviceNo: h('#serviceNo').html(),
			logList: h('#logList').val(),
			submitStatus:submitStatus
		})
	});

	// 图片信息列表
	h('#picList').tap(function() {
		console.log("==================="+h('#helpId').val())
		app.hideSoftKeybord()
		app.jumpTo('../../picture/list.html', 'view/service/picture/list.html', {
			helpId: h('#helpId').val(),
			serviceNo: h('#serviceNo').html(),
			submitStatus:submitStatus
		});
	});

	// 培训信息
	h('#trainInfo').tap(function() {
		app.hideSoftKeybord()
		app.showWaiting()
		ajaxGet(BASE_URL + 'cc/ServiceDetails/selectTrainPeople', {
			serviceNo: h('#serviceNo').html(),
		}, function(data) {
			app.closeWaiting()
			if (data.code === 200) {
				
					app.jumpTo('train.html', 'view/service/report/fieldservice/train.html', {
						serviceReportId: h('#id').val(),
						helpId: h('#helpId').val(),
						serviceNo: h('#serviceNo').html(),
						enginnerId: h('#enginnerId').val(),
						trainType: h('#trainType').val(),
						trainTypeName: h('#trainTypeName').val(),
						trainNum: h('#trainNum').val(),
						trainFse: h('#trainFse').val(),
						trainFseCode: h('#trainFseCode').val(),
						trainHour: h('#trainHour').val(),
						trainStart: h('#trainStart').val(),
						trainEnd: h('#trainEnd').val(),
						trainPlace: h('#trainPlace').val(),
						trainPlaceName: h('#trainPlaceName').val(),
						otherPlace: h('#otherPlace').val(),
						trainObject: h('#trainObject').val(),
						trainObjectName: h('#trainObjectName').val(),
						cusLevel: h('#cusLevel').val(),
						cusLevelName: h('#cusLevelName').val(),
						fseLevel: h('#fseLevel').val(),
						fseLevelName: h('#fseLevelName').val(),
						jourHour: h('#jourHour').val(),
						aeFse: h('#aeFse').val(),
						submitStatus: submitStatus
					})
					
				/* if (data.data.length > 0) {
				} else {
					app.toast("当前服务单没有实习生")
				} */
			} else {
				if (data.msg) {
					app.toast(data.msg);
				} else {
					app.toast();
				}
			}
		}, function(errorMsg) {
			app.closeWaiting();
			app.toast(errorMsg);
		});
	});

	// 服务费用
	h('#feeInfo').tap(function() {
		app.hideSoftKeybord()
		var chargeHours = h('#chargeHours').val();
		if (!chargeHours) {
			app.toast('请输入收费小时数')
			return;
		}

		var checkInt = /^\d+(?=\.{0,1}\d+$|$)/;
		if(!checkInt.test(chargeHours)){
			app.toast('请输入大于等于0的收费小时数')
			return;
		}

		app.jumpTo('fee.html', 'view/service/report/fieldservice/fee.html', {
			submitStatus: submitStatus,
			serviceReportId: h('#id').val(),
			helpId: h('#helpId').val(),
			serviceNo: h('#serviceNo').html(),
			enginnerId: h('#enginnerId').val(),
			bu: h('#bu').val(),
			city: h('#city').val(),
			prov: h('#prov').val(),
			noticeId: h('#noticeId').val(),
			chargeHours
		});
	});

	// MD相关问题
	h('#md').tap(function() {
		app.hideSoftKeybord()
		app.jumpTo('md.html', 'view/service/report/fieldservice/md.html', {
			submitStatus: submitStatus,
			serviceReportId: h('#id').val(),
			helpId: h('#helpId').val(),
			serviceNo: h('#serviceNo').html(),
			enginnerId: h('#enginnerId').val(),
			quesOne: h('#quesOne').val(),
			quesTwo: h('#quesTwo').val(),
			quesThree: h('#quesThree').val(),
			quesFour: h('#quesFour').val(),
			quesFive: h('#quesFive').val(),
			quesFiveone: h('#quesFiveone').val()
		})
	});

	// 备件列表
	h('#listPorts').tap(function() {
		app.hideSoftKeybord()
		app.jumpTo('./spareparts/list.html', 'view/service/report/fieldservice/spareparts/list.html', {
			serviceNo: h('#serviceNo').html(),
			phoneHelpId: h('#helpId').val(),
			isWarranty: h('#isWarranty').val(),
			type: 1,
			submitStatus: submitStatus
		})
	})

	// 添加备件
	h('#addPorts').tap(function() {
		app.hideSoftKeybord()
		app.jumpTo('./spareparts/add.html', 'view/service/report/fieldservice/spareparts/add.html', {
			serviceNo: h('#serviceNo').html(),
			phoneHelpId: h('#helpId').val(),
			isWarranty: h('#isWarranty').val(),
			type: 1
		})
	})

	// 服务结果
	h('#serviceResultsName').tap(function() {
		app.hideSoftKeybord()
		app.showWaiting()
		var userPicker = new mui.PopPicker();
		// [{"text":"完成","value":"1"},{"text":"未完成","value":"2"}]
		ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
			tableName: 'ServiceResult',
			engineerId: app.getUser().enginnerId
		}, function(data) {
			app.closeWaiting()
			console.log(JSON.stringify(data))
			if (!data) {
				app.toast("无服务结果数据")
				return
			}
			userPicker.setData(data);
			userPicker.show(function(items) {

				if (h('#serviceResults').val() != '1' && items[0].value === '1') {
					h('#suspendType').parent().hide();
					h('#suspendType').val('')
					h('#suspendTypeName').html('请选择')
					h('#suspendSonType').parent().hide();
					h('#suspendSonType').val('')
					h('#suspendSonTypeName').html('请选择')
					h('#workSuspendReason').parent().hide();
					h('#workSuspendReason').val('')
					h('#concernReason').parent().show();
					h('#concernReason').val('')
					var self = plus.webview.currentWebview();
					if (self.subServiceType == '安装') {
						h('#eqSignDiv').show()
					} else {
						h('#eqSignDiv').hide();
						var eqSigns = document.getElementsByName("eqSign");
						for (var i = 0; i < eqSigns.length; i++) {
							eqSigns[i].checked = false;
						}
					}
				} else if (h('#serviceResults').val() != '2' && items[0].value === '2') {
					h('#suspendType').parent().show();
					h('#suspendType').val('')
					h('#suspendTypeName').html('请选择')
					h('#suspendSonType').parent().show();
					h('#suspendSonType').val('')
					h('#suspendSonTypeName').html('请选择')
					h('#workSuspendReason').parent().show();
					h('#workSuspendReason').val('')
					h('#concernReason').parent().show();
					h('#concernReason').val('')
					h('#eqSignDiv').hide();
					var eqSigns = document.getElementsByName("eqSign");
					for (var i = 0; i < eqSigns.length; i++) {
						eqSigns[i].checked = false;
					}
				}
				h('#serviceResultsName').html(items[0].text)
				h('#serviceResults').val(items[0].value)
				userPicker.dispose()
			});
		});
	});

	// 工作类型
	h('#workTypeName').tap(function() {
		app.hideSoftKeybord()
		app.showWaiting()
		var userPicker = new mui.PopPicker();
		// [{"text":"Phone Support 电话支持","value":"1"},{"text":"Exhibition 展览会","value":"2"},{"text":"Office work 办公室","value":"3"},{"text":"Internal meeting 内部会议","value":"4"}]
		ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
			tableName: 'WorkTypeSDG',
			engineerId: app.getUser().enginnerId
		}, function(data) {
			app.closeWaiting()
			console.log(JSON.stringify(data))
			if (!data) {
				app.toast("无工作类型数据")
				return
			}
			userPicker.setData(data);
			userPicker.show(function(items) {
				h('#workTypeName').html(items[0].text)
				h('#workType').val(items[0].value)
				userPicker.dispose()
			});
		});
	})

	// 中断类型
	h('#suspendTypeName').tap(function() {
		app.hideSoftKeybord()
		app.showWaiting()
		h('#suspendSonTypeName').html('请选择');
		h('#suspendSonType').val('');
		var userPicker = new mui.PopPicker();
		// [{"text":"客户原因","value":"11"},{"text":"服务团队原因","value":"12"},{"text":"仪器本身原因","value":"13"},{"text":"软件原因","value":"14"},{"text":"备件原因","value":"15"},{"text":"工具原因","value":"16"},{"text":"跨月工时上传 ","value":"17"}]
		ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
			tableName: 'ServiceStopType',
			engineerId: app.getUser().enginnerId
		}, function(data) {
			app.closeWaiting()
			console.log(JSON.stringify(data))
			if (!data) {
				app.toast("无中断类型数据")
				return
			}
			userPicker.setData(data);
			userPicker.show(function(items) {
				h('#suspendTypeName').html(items[0].text)
				h('#suspendType').val(items[0].value)
				userPicker.dispose()
			});
		});
	})

	// 中断子类型
	h('#suspendSonTypeName').tap(function() {
		app.hideSoftKeybord()
		app.showWaiting()
		var userPicker = new mui.PopPicker();
		// [{"text":"客户条件不具备","value":"1"},{"text":"新出现的不同故障","value":"10"},{"text":"硬件不兼容","value":"11"},{"text":"需多人同时操作维修","value":"12"},{"text":"需升级的软件服务","value":"13"},{"text":"备件缺货","value":"14"},{"text":"备件未按计划及时到达 ","value":"15"},{"text":"备件错发或漏发 ","value":"16"},{"text":"备件到货即坏 ","value":"17"},{"text":"工具不可用 ","value":"18"},{"text":"月底上传当月工时 ","value":"19"},{"text":"费用问题","value":"2"},{"text":"改期/取消上门服务","value":"3"},{"text":"做样观察","value":"4"},{"text":"报修描述不准确","value":"5"},{"text":"产品不熟悉","value":"6"},{"text":"人手不足","value":"7"},{"text":"仪器性能问题","value":"8"},{"text":"需升级的硬件问题","value":"9"}]
		ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
			tableName: 'ServiceStopSubType',
			engineerId: app.getUser().enginnerId,
			parentValue: h('#suspendType').val()
		}, function(data) {
			app.closeWaiting()
			console.log(JSON.stringify(data))
			if (!data) {
				app.toast("无中断子类型数据")
				return
			}
			userPicker.setData(data);
			userPicker.show(function(items) {
				h('#suspendSonTypeName').html(items[0].text)
				h('#suspendSonType').val(items[0].value)
				userPicker.dispose()
			});
		});
	})

	// 保存草稿
	h('#saveBtn').tap(function() {
		h('#saveBtn').attr('disabled','disabled');
		app.hideSoftKeybord()
		saveData("正在保存...");
	});

	// 正式提交
	h('#submitBtn').tap(function() {
		app.hideSoftKeybord();
		h('#submitBtn').attr('disabled','disabled');
		saveData("正在提交...", function() {
			submitData();
		});
	});
}


/**
 * 查询现场服务报告详情
 * 
 * @param {Object} serviceNo
 * @param {Object} enginnerId
 * @param {Object} reportId
 */
function viewReport(serviceNo, enginnerId, reportId) {
	app.showWaiting();
	ajaxGet(BASE_URL + 'cc/service/report/detailServiceReport', {
		serviceNo,
		enginnerId,
		reportId
	}, function(data) {
		console.log(data)
		app.closeWaiting()
		if (data.code === 200) {
			var reportInfo = data.data.reportInfo;

			
			if (data.data.id) {
				h('#reportId').val(data.data.id)
			}
			if (reportInfo.id) {
				h('#id').val(reportInfo.id)
			}
			if (data.data.planId) {
				h('#planId').val(data.data.planId);
			}
			if (data.data.noticeId) {
				h('#noticeId').val(data.data.noticeId);
			}
			if (data.data.enginnerId) {
				h('#enginnerId').val(data.data.enginnerId);
			}
			if (data.data.fseName) {
				h('#fseName').val(data.data.fseName);
			}
			if (!JS.IsNullOrEmpty(reportInfo.helpId)) {
				h('#helpId').val(reportInfo.helpId);
			}
			

			// 现场服务报告主页面信息
			// if (h('#serviceTypeName').html() == '请选择') {
			if (reportInfo.serviceTypeName!='' && reportInfo.serviceTypeName!=undefined) {
				h('#serviceType').val(reportInfo.serviceType);
				h('#serviceTypeName').html(reportInfo.serviceTypeName || '请选择');
			}

			if(h('#serviceTypeName').html() == "安装"|| h('#serviceTypeName').html() == "保内"){
				h('#feeInfo').parent().hide()
			}else {
				h('#feeInfo').parent().show()
			}

			if (reportInfo.problem) {
				h('#problem').val(reportInfo.problem);
			}
			h('#startTravelDate').html(reportInfo.startTravelDate || '请选择出发时间');
			h('#orderReceivedDate').html(reportInfo.orderReceivedDate || '请选择接收任务时间');
			h('#onSiteData').html(reportInfo.onSiteData || '请选择到达现场时间');
			h('#startWorkingTime').html(reportInfo.startWorkingTime || '请选择工作开始时间');
			h('#endWorkingTime').html(reportInfo.endWorkingTime || '请选择工作结束时间');
			var totalWorkingHours = reportInfo.totalWorkingHours;
			if (emptyStr(totalWorkingHours) != "") {
				var workingHours = Number(totalWorkingHours).toFixed(2);
				h('#totalWorkingHours').val(workingHours);
			} else {
				h('#totalWorkingHours').val("0.00");
			}
			// h('#travelTime').val(reportInfo.travelTime);
			// edit by wlf 2020-05-19 旅途小时数保留2位小数
			var time = reportInfo.travelTime;
			if (emptyStr(time) != "") {
				var number = Number(time).toFixed(2);
				h('#travelTime').val(number);
			} else {
				h('#travelTime').val("0.00");
			}
			
			h('#actionTaken').val(reportInfo.actionTaken);
			h('#chargeHours').val(reportInfo.chargeHours);
			h('#results').val(reportInfo.results);
			h('#engineersAdvis').val(reportInfo.engineersAdvis);
			h('#enProblemDescription').val(reportInfo.enProblemDescription);
			h('#serviceResults').val(reportInfo.serviceResult);
			h('#serviceResultsName').html(reportInfo.serviceResultName || '请选择');

			if (reportInfo.serviceResult == '1') {
				h('#concernReason').val(reportInfo.concernReason);
				h('#concernReason').parent().show();
				if (reportInfo.serviceResultName == '完成') {
					if (reportInfo.eqSign) {
						var eqSigns = reportInfo.eqSign.split(',');
						for (var i = 0; i < eqSigns.length; i++) {
							document.querySelector(`input[name='eqSign'][value='${eqSigns[i]}']`).checked = true;
						}
						h('#eqSignDiv').show()
					}
				}
			} else if (reportInfo.serviceResult == '2') {
				h('#suspendType').val(reportInfo.suspendType);
				h('#suspendTypeName').html(reportInfo.suspendTypeName || '请选择');
				h('#suspendType').parent().show()

				h('#suspendSonType').val(reportInfo.subSuspendType);
				h('#suspendSonTypeName').html(reportInfo.subSuspendTypeName || '请选择');
				h('#suspendSonType').parent().show()

				h('#workSuspendReason').val(reportInfo.workSuspendReason);
				h('#workSuspendReason').parent().show();

				h('#concernReason').val(reportInfo.concernReason);
				h('#concernReason').parent().show();
			}

			// 培训信息
			h('#trainType').val(reportInfo.trainType);
			h('#trainTypeName').val(reportInfo.trainTypeName);
			h('#trainNum').val(reportInfo.trainNum);
			h('#trainFse').val(reportInfo.trainFse);
			h('#trainFseCode').val(reportInfo.trainFseCode);
			h('#trainHour').val(reportInfo.trainHour);
			h('#trainStart').val(reportInfo.trainStart);
			h('#trainEnd').val(reportInfo.trainEnd);
			h('#trainPlace').val(reportInfo.trainPlace);
			h('#trainPlaceName').val(reportInfo.trainPlaceName);
			h('#otherPlace').val(reportInfo.otherPlace);
			h('#trainObject').val(reportInfo.trainObject);
			h('#trainObjectName').val(reportInfo.trainObjectName);
			h('#cusLevel').val(reportInfo.cusLevel);
			h('#cusLevelName').val(reportInfo.cusLevelName);
			h('#fseLevel').val(reportInfo.fseLevel);
			h('#fseLevelName').val(reportInfo.fseLevelName);
			h('#jourHour').val(reportInfo.jourHour);
			h('#aeFse').val(reportInfo.aeFse);

			// 服务费用


			// MD相关问题
			h('#enginnerId').val(reportInfo.enginnerId + '');
			h('#quesOne').val(reportInfo.quesOne + '');
			h('#quesTwo').val(reportInfo.quesTwo + '');
			h('#quesThree').val(reportInfo.quesThree + '');
			h('#quesFour').val(reportInfo.quesFour + '');
			h('#quesFive').val(reportInfo.quesFive + '');
			h('#quesFiveone').val(JS.IsNullOrEmpty(reportInfo.quesFiveone) ? '' : reportInfo.quesFiveone + '');

			// 关联的日志信息
			h('#logList').val(JSON.stringify(reportInfo.logList))

			h('#mui-content').show()
		} else {
			if (data.msg) {
				app.toast(data.msg)
			} else {
				app.toast()
			}
		}
	}, function(errorMsg) {
		app.closeWaiting()
		app.toast(errorMsg)
	});
}

/**
 * 保存数据
 * @param {Object} callBack
 */
function saveData(loadingTips, callBack) {
	var self = plus.webview.currentWebview();
	if (!app.getNetworkState()) {
		app.toast("无网络")
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}

	var enginnerId = app.getUser().enginnerId;
	var fseName = app.getUser().name;
	var id = h('#id').val();
	var noticeServiceType = h('#noticeServiceType').val();
	var serviceNo = h('#serviceNo').html();
	var noticeId = h('#noticeId').val();
	var planId = h('#planId').val();
	var helpId = h('#helpId').val();
	var problem = h('#problem').val();
	var serviceType = h('#serviceType').val();
	var serviceTypeName = h('#serviceTypeName').html();
	var chargeHours = h('#chargeHours').val();
	var startTravelDate = h('#startTravelDate').html();
	var orderReceivedDate = h('#orderReceivedDate').html();
	var onSiteData = h('#onSiteData').html();
	var startWorkingTime = h('#startWorkingTime').html();
	var endWorkingTime = h('#endWorkingTime').html();
	var totalWorkingHours = h('#totalWorkingHours').val();
	var travelTime = h('#travelTime').val();
	var actionTaken = h('#actionTaken').val();
	var results = h('#results').val();
	var engineersAdvis = h('#engineersAdvis').val();
	var serviceResult = h('#serviceResults').val();
	var serviceResultName = h('#serviceResultsName').html();
	var enProblemDescription = h('#enProblemDescription').val();
	var suspendType = h('#suspendType').val();
	var suspendTypeName = h('#suspendTypeName').html();
	var subSuspendType = h('#suspendSonType').val();
	var subSuspendTypeName = h('#suspendSonTypeName').html();
	var workSuspendReason = h('#workSuspendReason').val();
	var concernReason = h('#concernReason').val();
	var eqSign = JS.GetCheckboxValue('eqSign') || '';
	var isWarranty = h('#isWarranty').val();
	var mdsign = h('#mdsign').val() || 0;
	var quesOne = h('#quesOne').val();
	var quesTwo = h('#quesTwo').val();
	var quesThree = h('#quesThree').val();
	var quesFour = h('#quesFour').val();
	var quesFive = h('#quesFive').val();
	var quesFiveone = h('#quesFiveone').val();
	var bu = h('#bu').val()
	var prov = h('#prov').val()
	var city = h('#city').val()

	
	if (!problem) {
		app.toast('请输入故障');
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}
	if (!chargeHours) {
		app.toast('请输入收费小时数');
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}
	if (!results) {
		app.toast('请输入结果');
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}
	if ((noticeServiceType == '安装' || isWarranty == '保内') && !enProblemDescription) {
		app.toast('请输入英文故障描述');
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}
	if ((serviceTypeName == '安装' || serviceTypeName == '保内') && !enProblemDescription) {
		app.toast('请输入英文故障描述');
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return
	}
	/*if ((noticeServiceType == '安装' || isWarranty == '保内') && !enProblemDescription) {
		app.toast('请输入英文故障描述');
		return
	}*/
	if (!serviceResult) {
		app.toast('请选择服务结果')
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		return false
	}
	if (serviceResult == "1") { // 已完成
		if (self.serviceType == "安装" && self.subServiceType == "安装" && !eqSign) {
			app.toast('请选择仪器贴标选项')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return false
		}
	} else if (serviceResult == "2") { // 未完成
		if (!suspendType) {
			app.toast('请选择中断类型')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return false
		}
		if (!subSuspendType) {
			app.toast('请选择中断子类型')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return false
		}
		if (!workSuspendReason) {
			app.toast('请输入工作中断原因')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return false
		}
	}

	if (self.serviceType == "维修" && self.subServiceType == "维修" && mdsign == "1") {		
		if (
			!quesOne || 
			!quesTwo || 
			!quesThree || 
			!quesFour || 
			!quesFive || 
			quesOne == "null" || 
			quesTwo == "null" || 
			quesThree == "null" || 
			quesFour == "null" || 
			quesFive == "null"
		) {
			app.toast('请回答医疗器械可疑不良事件相关问题')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return
		} else if (quesFive == '1' && (!quesFiveone || quesFiveone == "null")) {
			app.toast('请回答医疗器械可疑不良事件相关问题')
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			return
		}
	}
	
	var params = {
		enginnerId,
		fseName,
		id,
		serviceNo,
		noticeId,
		planId,
		helpId,
		problem,
		serviceType,
		serviceTypeName,
		chargeHours,
		startTravelDate,
		orderReceivedDate,
		onSiteData,
		startWorkingTime,
		endWorkingTime,
		totalWorkingHours,
		travelTime,
		actionTaken,
		results,
		engineersAdvis,
		serviceResult,
		serviceResultName,
		enProblemDescription,
		suspendType,
		suspendTypeName,
		subSuspendType,
		subSuspendTypeName,
		workSuspendReason,
		concernReason,
		eqSign,
		isWarranty,
		bu,
		prov,
		city
	}

	if(typeof(params) == "object"){
		var code = String.fromCharCode(8198)
		Object.keys(params).forEach(function (key) {
			if (typeof(params[key]) == 'string'){
				var str = params[key].split(code).join(' ')
				params[key]=str
				str = null;
			}
			// params[key].split(code).join('!!!!!')

		})
		console.debug(params)
	}

	app.showWaiting(loadingTips)
	ajaxPost(BASE_URL + 'cc/service/report/editServiceReport', params, function(data) {
		// console.log(JSON.stringify(data))
		app.closeWaiting();
		if (data.code === 200) {
			h('#id').val(data.data.batchType)
			if (typeof callBack === "function") {
				callBack()
			} else {
				app.toast("保存成功");
				h('#saveBtn').removeAttr('disabled');
				h('#submitBtn').removeAttr('disabled');
				var workReportList = plus.webview.getWebviewById('view/service/report/work/workReportList.html')
				if (workReportList) {
					workReportList.evalJS("initData()")
				}
				mui.back()
			}
		} else {
			h('#saveBtn').removeAttr('disabled');
			h('#submitBtn').removeAttr('disabled');
			app.toast(data.msg)
		}
	}, function(err) {
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		app.closeWaiting()
		app.toast(err)
	});


}

/**
 * 提交数据
 */
function submitData() {
	ajaxGet(BASE_URL + 'cc/service/report/submitServiceReport', {
		id: h('#id').val(),
		enginnerId: app.getUser().enginnerId
	}, function(data) {
		app.closeWaiting()
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		if (data.code === 200) {
			app.toast("提交成功")			
			var serviceResults = h('#serviceResults').val();
			var self = plus.webview.currentWebview();
			// 提交完成的报告 删除当前服务单的本地离线数据 
			if(serviceResults == '1'){
				var planId = h('#planId').val();
				var enginnerId = app.getUser().enginnerId;
				var sqliteTool = new sqliteTools(); 								
				sqliteTool.openDatabase();
				sqliteTool.selectServiceByPlanId(enginnerId, planId, '', function(flag, offlineData, callBackData) {
					if (offlineData && offlineData.length > 0) {
						sqliteTool.deleteServiceData(offlineData[0].planId, function(flag) {
							console.log("删除本地数据"+flag)
							sqliteTool.closeDB();
						})
					} else {
						sqliteTool.closeDB();
					}										
				});
			}
			
			if(self.planState && self.planState == '3' && serviceResults == '1'){
				var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
				if (checkedOutList) {
					checkedOutList.close();
				}
				var signInAddReport = plus.webview.getWebviewById('view/service/notice/signInAddReport.html');
				if (signInAddReport) {
					signInAddReport.close();
				}
				var workReportList = plus.webview.getWebviewById('view/service/report/work/workReportList.html');
				if (workReportList) {
					workReportList.close();
				}
				var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
				if(indexFSE){
					indexFSE.evalJS('getList("1")')
				}
				var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
				if(conductList){
					conductList.evalJS('getList()')
				}
				var completedList = plus.webview.create('/view/service/notice/completedList.html','view/service/notice/completedList.html');
				completedList.show();
				self.close();
				return
			}
			
			var workReportList = plus.webview.getWebviewById('view/service/report/work/workReportList.html')
			if (workReportList) {
				workReportList.evalJS("initData()")
			}
			var maintenanceReport = plus.webview.getWebviewById('view/service/report/maintenanceReport.html')
			if (maintenanceReport) {
				maintenanceReport.evalJS("initData()")
			}
			mui.back()
		} else {
			app.toast(data.msg)
		}
	}, function(err) {
		h('#saveBtn').removeAttr('disabled');
		h('#submitBtn').removeAttr('disabled');
		app.closeWaiting()
		app.toast(err)
	})
}

/**
 * 初始化时间控件
 */
function initDateTimeControls() {
	// 出发时间
	new Rolldate({
		el: '#startTravelDate',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2015,
		endYear: 2050,
		trigger: 'click',
		lang: {
			title: '请选择出发时间',
		},
		confirm: function(date) {

		}
	});

	// 接收任务时间
	new Rolldate({
		el: '#orderReceivedDate',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2015,
		endYear: 2050,
		trigger: 'click',
		lang: {
			title: '请选择接收任务时间',
		},
		confirm: function(date) {

		}
	});

	// 到达现场时间
	new Rolldate({
		el: '#onSiteData',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2015,
		endYear: 2050,
		trigger: 'click',
		lang: {
			title: '请选择到达现场时间',
		},
		confirm: function(date) {

		}
	});

	// 工作开始时间
	new Rolldate({
		el: '#startWorkingTime',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2015,
		endYear: 2050,
		trigger: 'click',
		lang: {
			title: '请选择工作开始时间',
		},
		confirm: function(date) {

		}
	})

	// 工作结束时间
	new Rolldate({
		el: '#endWorkingTime',
		format: 'YYYY-MM-DD hh:mm',
		beginYear: 2015,
		endYear: 2050,
		trigger: 'click',
		lang: {
			title: '请选择工作结束时间',
		},
		confirm: function(date) {

		}
	})
}
